home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
jazlib.arc
/
JAZPRINT.DMO
< prev
next >
Wrap
Text File
|
1988-12-18
|
8KB
|
277 lines
/*
┌────────────────────────────────────────────────────────────────────────────┐
│ Title : jazprint.dmo │
│ Purpose : Allow multiple printing of programs, with wildcards and various │
│ │
│ formatting options. │
│ -d specifies double strike printing │
│ -e specifies emphasized printing │
│ -t specifies title of document + time and date │
│ -w specifies wide (compressed) listing │
│ -n specifies to number the lines │
│ -u specifies user chars to send (in hex). i.e jazprint *.* -u 1b471b45 │
│ -mn specifies multiple copies where n is the number of copies │
│ │
│Written using Lattice C v 2.15e, translated to Microsoft C v3.0 on 1/15/86 │
│Version changed to use stdout for printing on 7/10/86 │
│ │
│ Written by Jack Zucker - 75766,1336 301-794-5950 │
└────────────────────────────────────────────────────────────────────────────┘
*/
#include <stdio.h> /* standard header file */
#include <time.h> /* Ms C time struct */
#include <stdlib.h> /* standard functions */
#include <ctype.h> /* isdigit, islower, etc */
#include <jaz.h> /* standard jaz functions */
#include <jzdirect.h> /* jz directory stuff */
#define VERSION "3.0"
#define FORMFEED 0x0c /* form feed */
#define PGLEN 60 /* length of a page */
#define COMPRS 0x0f /* epson compressed code */
#define BUFSIZE 255 /* Number of chars to read */
#define ESC 0x1b /* hex esc code */
#define DBL 71 /* epson double strike code */
#define EMPH 69 /* epson emphasized code */
int colno,lineslft,width = 81;
struct tm *wtime;
char *glbtime;
/* switches */
int NUMBER = 0,WIDE = 0,TITLE = 0;
int DOUBLE = 0,EMPHASIZ = 0,MULTIPLE = 1;
char USERSTR[64]; /* string for user printing */
char mask[13]; /* global variables */
char wpath[64],wtemp[64];
int gpage;
main (argc,argv)
int argc;
char **argv;
{
TDIR wdir;
char *HEX= "0123456789ABCDEF";
char buf[BUFSIZE + 1],*s,*ch;
char *p,*malloc();
long wtics;
int c,n,w;
FILE *fd;
int werr;
int werror = 0; /* command error flag */
char wstr[64];
fprintf(stderr,"\n\n%s%s%s\n","JAZPRINT v",VERSION,
" by JazSoft (Jack A. Zucker) 301-794-5950 | CIS:75766,1336");
if (argc > 1) {
strcpy(mask,*++argv); /* get full path name */
jzprsfil(mask,wpath,wstr); /* parse out path and file name */
time(&wtics);
wtime = localtime(&wtics);
glbtime = asctime(wtime);
w = strlen(glbtime);
glbtime[--w] = '\0';
while (--argc > 0 && (*++argv)[0] == '-') /* parse through options */
for (s = argv[0]+1; *s ; s ++)
switch(toupper(*s)) {
case 'W' : /* wide printing */
WIDE = 1;
break;
case 'N' : /* number lines */
NUMBER = 1;
break;
case 'T' :
TITLE = 1; /* title and heading */
break;
case 'D' :
DOUBLE = 1; /* double strike */
break;
case 'E' :
EMPHASIZ = 1; /* emphasized */
break;
case 'M' :
MULTIPLE = 0; /* assume no copies */
s ++;
while (isdigit(*s))
MULTIPLE = MULTIPLE * 10 + (*s++ - 48);
s --;
break;
case 'U' :
p = *(argv+1); /* get pointer to hex string */
if (strlen(p) & 1) { /* odd length of hex string */
fprintf(stderr,"\nHex digits must be two chars long each !");
werror = 1; /* set error flag */
break;
}
*USERSTR = 0; /* start out with null string */
w = 0;
while (*p) { /* convert hex to binary to char */
c = index(HEX,toupper(*p)) << 4 ; /* get first hex digit */
p++;
c += index(HEX,toupper(*p));
p++;
USERSTR[w++] = c; /* store char in string */
}
USERSTR[w] = 0; /* terminate string */
break;
default: /* invalid option */
fprintf(stderr,"\nIllegal option %c",*s);
werror = 1;
break;
}
}
else
werror = 1;
/* help or bad options */
if (werror || (mask[0] == '?' && strlen(mask) == 1)) {
fprintf(stderr,"\nusage: JAZPRINT [filespec] (including wildcards)\
[-detwnum]\n");
fprintf(stderr,"\n\t-d specifies double strike printing");
fprintf(stderr,"\n\t-e specifies emphasized printing");
fprintf(stderr,"\n\t-t specifies title of document + time and date");
fprintf(stderr,"\n\t-w specifies wide (compressed) listing");
fprintf(stderr,"\n\t-n specifies to number the lines");
fprintf(stderr,"\n\t-u specifies user chars to send (in hex). i.e \
jazprint *.* -u 1B471B45");
fprintf(stderr,"\n\t-mn specifies multiple copies where n is the number \
of copies\n");
exit(1);
}
while (MULTIPLE -- ) { /* allow for mult copies */
werr = jzfndfst(mask,32,&wdir); /* get first matching file */
if (!werr)
do { /* until no more files */
strcpy(wtemp,wpath);
strcat(wtemp,wdir.name);
if (!( fd = fopen(wtemp,"r"))) { /* open for read only */
/* bad file or it ain't there */
fprintf(stderr,"\nCan't find %s",wdir.name);
exit(1);
}
fprintf(stderr,"\nPrinting: %s . . .",wdir.name);
getflags(); /* look at switch settings */
gpage = 0; /* set page for this file */
formfeed (wdir.name); /* page feed */
/* while not eof do begin */
while ( (ch = fgets(buf,BUFSIZE,fd)) ) {
if (linepr(buf,wdir.name)) continue; /* main print routine */
if (! lineslft) formfeed (wdir.name); /* formfeed if appropriate */
}
printf("\n"); /* flush print buffer */
fclose(fd); /* close input file */
werr = jzfndnxt(&wdir); /* get next matching file */
} while (! werr);
else {
fprintf(stderr,"No match for %s",mask);
exit(1);
}
}
}
linepr (string,fname)
char *string;
char *fname;
{
char c;
int ffflag = 0;
static int wline = 0;
while ( c = *string ++) {
if ( ( ! colno ) && NUMBER ) {
printf("%d",++wline);
colno += 6;
}
switch (c) {
case FORMFEED :
ffflag = 1;
break;
case '\n' :
printf("\n");
colno = 0;
if (! (lineslft --)) formfeed (fname);
break;
case '\t' :
do {
printf(" ");
colno ++;
if (! ( ( (NUMBER) ? width - 8 : width) - colno ) ) {
printf("\n");
if (! (lineslft --)) formfeed (fname);
colno = 0;
}
} while ( colno % 8 );
break;
default:
printf("%c",c);
colno ++;
if (! ( ( (NUMBER) ? width - 8 : width) - colno ) ) {
printf("\n");
if (! (lineslft --)) formfeed (fname);
colno = 0;
}
} /* switch */
}
if (ffflag) formfeed (fname);
return ffflag;
}
formfeed (fname)
char *fname;
{
printf("%c",FORMFEED); /* go to top of next page */
if (TITLE) heading(fname);
lineslft = PGLEN - 4;
colno = 0;
}
#define EMPHON "\n\x1bE\x1bG"
#define EMPHOFF "\n\n\n\r\x1bF\x1bH"
heading(fname)
char *fname;
{
gpage ++;
printf("%sListing of %s on %s PAGE: %5d%s",EMPHON,fname,glbtime,
gpage,EMPHOFF);
getflags();
}
getflags()
{
if (WIDE) {
printf("%c",COMPRS);
width = 133;
}
if (DOUBLE) printf("%c%c",ESC,DBL);
if (EMPHASIZ) printf("%c%c",ESC,EMPH);
printf(*USERSTR ? "%s" : "" ,USERSTR);
}